<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/3/24
 * Time: 15:55
 */

namespace Bbs\Api;

use Bbs\Model\BbsMemberViewModel;
use Bbs\Model\ForumAdmingroupModel;
use Bbs\Model\VUserInfoModel;
use Common\Api\Api;

class BbsMemberApi extends Api{

    /**
     * 添加
     */
    const ADD = "Bbs/BbsMember/add";
    /**
     * 保存
     */
    const SAVE = "Bbs/BbsMember/save";
    /**
     * 保存根据ID主键
     */
    const SAVE_BY_ID = "Bbs/BbsMember/saveByID";

    /**
     * 删除
     */
    const DELETE = "Bbs/BbsMember/delete";

    /**
     * 查询
     */
    const QUERY = "Bbs/BbsMember/query";
    /**
     * 查询一条数据
     */
    const GET_INFO = "Bbs/BbsMember/getInfo";

    /**
     * 插入多条数据
     */
    const ADD_ALL = "Bbs/BbsMember/addAll";

    /**
     * 无分页查询
     */
    const QUERY_NO_PAGING = "Bbs/BbsMember/queryNoPaging";

    /**
     * 取用户信息
     */
    const GET_USER_INFO = "Bbs/BbsMember/getUserInfo";

    /**
     * 取用户信息分页
     */

    const QUERY_MEMBER = "Bbs/BbsMember/memberQuery";

    protected function _init(){
        $this -> model = new BbsMemberViewModel();
    }


    /**
     * 取用户信息
     */
    public function getUserInfo($uid){

        $model = new VUserInfoModel();

        $map = array(
            'id' => $uid
        );

        $field = "id,username,nickname,head";
        $result = $model->where($map)->field($field)->find();

        if($result === false){
            $error = $model->getDbError();
            return $this->apiReturnErr($error);
        }

        $info = $result;

        //查权限
        $map = array('uid'=>$uid);
        $info['group'] = NULL;
        $result = apiCall(ForumUserAdmingroupApi::GET_INFO,array($map));
        if($result['status']){
            if(!is_null($result['info'])){
                //查询权限详情
                $fid = $result['info']['fid'];
                $map = array('adminid'=>$result['info']['adminid']);
                $result = apiCall(ForumAdmingroupApi::GET_INFO,array($map));
                if($result['status']){
                    if(!is_null($result['info'])){
                        $info['group'] = $result['info'];
                        $info['group']['fid'] = $fid;
                    }
                }else{
                    return $this->apiReturnErr($result['info']);
                }
            }
        }

        return $this->apiReturnSuc($info);

    }


}